package com.film.service.impl.movie;

import com.alibaba.fastjson.JSONObject;
import com.film.service.movie.DeleteMovieByIdService;
import com.film.utils.MySqlConnection;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.sql.Statement;

@Service
public class DeleteMovieByIdServiceImpl implements DeleteMovieByIdService {
    @Override
    public JSONObject delete(Integer movieId) throws SQLException {
        //删除Movie表
        String sql = "delete from Movie where id = " + movieId;
        Statement stmt = MySqlConnection.connect.createStatement();
        stmt.execute(sql);

        //删除User_Favor_Movie表
        sql = "delete from User_Favor_Movie where movie_id = " + movieId;
        stmt.execute(sql);

        //删除Movie_Comments表
        sql = "delete from Movie_Comments where movie_id = " + movieId;
        stmt.execute(sql);
        stmt.close();

        JSONObject resp = new JSONObject();
        resp.put("error_messafe", "删除成功");
        return resp;
    }
}
